/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JDialogPopupHelpInfo.java
 *
 * Created on 04-dic-2011, 16:39:23
 */
package com.ufps.cuatro.vistas.util;

import com.ufps.cuatro.CuatroApp;
import com.ufps.cuatro.util.MensajeAyudaVentana;
import com.ufps.cuatro.util.MensajeLineaAyudaVentana;
import com.ufps.cuatro.util.Utileria;
import java.util.ArrayList;

/**
 *
 * @author Carlos A. Torres C. 
 */
public class JDialogPopupHelpInfo extends javax.swing.JDialog {
    private static final long serialVersionUID = 7832627097091623393L;
    
    private ArrayList<MensajeAyudaVentana> objMensajes;    

    /** Creates new form JDialogPopupHelpInfo */
    public JDialogPopupHelpInfo(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();        
    }
    
    public JDialogPopupHelpInfo(ArrayList<MensajeAyudaVentana> objMensajes, String strTitle){
        super(CuatroApp.getApplication().getMainFrame(), false);        
        initComponents(); 
        this.setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE);
        this.setIconImage(Utileria.leerIconoAppEnImagen(Utileria.MODO_16x16).getImage());
        this.setTitle(this.getTitle() + " - " + strTitle);                
        this.objMensajes = objMensajes;
        this.cargarMensajes();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jEditorPane1 = new javax.swing.JEditorPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Ayuda Emergente - Cuatro");
        setModalExclusionType(java.awt.Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
        setResizable(false);
        setType(java.awt.Window.Type.POPUP);

        jScrollPane1.setToolTipText("Ayuda");
        jScrollPane1.setViewportBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jEditorPane1.setContentType("text/html");
        jEditorPane1.setEditable(false);
        jEditorPane1.setName("jEditorPane1"); // NOI18N
        jScrollPane1.setViewportView(jEditorPane1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 453, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(JDialogPopupHelpInfo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(JDialogPopupHelpInfo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(JDialogPopupHelpInfo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(JDialogPopupHelpInfo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                JDialogPopupHelpInfo dialog = new JDialogPopupHelpInfo(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    
    
    private void cargarMensajes(){
        this.jEditorPane1.setContentType("text/html");
        String strTexto = "";
        if(objMensajes.isEmpty()){
            strTexto = "Ayuda No Disponible. Pilas Dolly aún falta";
        }
        else{
            for(MensajeAyudaVentana objMsg : this.objMensajes){  
                if(!objMsg.isConcatenado()){
                    strTexto += objMsg.getStrTitulo();
                } 
                for(MensajeLineaAyudaVentana objLineaMsg : objMsg.getObjLineas()){  
                    strTexto += objLineaMsg.getStrContenido();
                }            
            }
        }
        this.jEditorPane1.setText(strTexto);
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JEditorPane jEditorPane1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
